<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <script type="text/javascript" src="d3.js"></script>
    <script type="text/javascript" src="NetworkGraph.min.js"></script>
    <style>
        html {
            height: 100%;
        }
        body {
            width: 100%;
            height: 100%;
        }
        #vis {
            width: 100%;
            height: 100%;
            margin: 0 auto;
        }
    </style>
    <title>NetworkGraph</title>
</head>
<body>
    <svg id="vis"></svg>
    <script>
        var data0 = {
            "nodes": [
                { "id": 0, "label": "Person",  "size": 30 },
                { "id": 1, "label": "Company", "size": 10 },
                { "id": 2, "label": "Company", "size": 15 },
                { "id": 3, "label": "Company" },
                { "id": 4, "label": "Company", "size": 17 },
                { "id": 5, "label": "Company", "size": 40 },
                { "id": 6, "label": "Company", "size": 35 }
            ],
            "links": [
                { "type": "EMPLOY", "source": 0, "target": 1 },
                { "type": "EMPLOY", "source": 0, "target": 1 },
                { "type": "EMPLOY", "source": 1, "target": 0 },
                { "type": "EMPLOY", "source": 1, "target": 2 },
                { "type": "EMPLOY", "source": 2, "target": 3 },
                { "type": "EMPLOY", "source": 0, "target": 2 },
                { "type": "EMPLOY", "source": 3, "target": 4 },
                { "type": "EMPLOY", "source": 3, "target": 4 },
                { "type": "EMPLOY", "source": 3, "target": 6 },
                { "type": "EMPLOY", "source": 5, "target": 0 },
                { "type": "EMPLOY", "source": 3, "target": 0 },
            ]
        };
        var data1 = {
            "nodes": [
                { "id": 10, "label": "Person"  },
                { "id": 11, "label": "Company" },
                { "id": 12, "label": "Company" },
                { "id": 13, "label": "Company" },
                { "id": 14, "label": "Person"  },
                { "id": 15, "label": "Company" },
                { "id": 16, "label": "Company" },
                { "id": 17, "label": "Company" }
            ],
            "links": [
                { "type": "EMPLOY", "source": 10, "target": 11 },
                { "type": "EMPLOY", "source": 11, "target": 12 },
                { "type": "EMPLOY", "source": 12, "target": 13 },
                { "type": "EMPLOY", "source": 12, "target": 14 },
                { "type": "EMPLOY", "source": 15, "target": 16 },
                { "type": "EMPLOY", "source": 17, "target": 15 },
                { "type": "EMPLOY", "source": 11, "target": 15 },
                { "type": "EMPLOY", "source": 12, "target": 16 }
            ]
        };
        var links = [
            { "source": 0 , "target": 10, "type": "" },
            { "source": 1 , "target": 11, "type": "" },
            { "source": 11, "target": 1 , "type": "" }
        ];
        var network_graph = new NetworkGraph("vis");
        var graph0 = network_graph.drawNetworkGraph(data0, "force", 300, 400);
        var graph1 = network_graph.drawNetworkGraph(data1, "radius", 900, 400);
        graph1.connectGraph(graph0, links);
        var node0 = {
            "id": 100,
            "label": "Company",
            "size": 50,
        };
        var node1 = {
            "id": 101,
            "label": "Company",
            "size": 30,
        };
        setTimeout(() => {
            // network.addNode(node);
            // network.addNode(node, x, y);
            graph0.addNode(node0, 100, 200);
            graph1.addNode(node1, 100, 200);
        }, 1000);
        setTimeout(() => {
            // network.addLink(node,    node,    node_type);
            // network.addLink(node_id, node_id, node_type);
            // network.addLink(node,    node_id, node_type);
            // network.addLink(node_id, node,    node_type);
            graph0.addLink(node0, 3, "TEST");
            graph1.addLink(node1, 16, "TEST");
        }, 2000);
        setTimeout(() => {
            // network.removeLink(link);
            graph0.removeLink(data0.links[0]);
            graph0.removeNode(5);
            graph1.removeLink(data1.links[2]);
            graph1.removeNode(15);
        }, 3000);
    </script>
</body>
</html>